package response

import "jgyApi/server/model/system"

type SysUserResponse struct {
	User system.AuthAdmin `json:"auth_admin"`
}

//type LoginResponse struct {
//	User      system.AuthAdmin `json:"auth_admin"`
//	Token     string         `json:"token"`
//	ExpiresAt int64          `json:"expiresAt"`
//}

type LoginResponse struct {
	ID          int64    `gorm:"column:id;type:int(11) unsigned;primaryKey;autoIncrement:true;comment:自增ID" json:"id"`
	Username    string   `gorm:"column:username;type:varchar(128);not null;comment:用户名" json:"username"`
	Realname    string   `gorm:"column:realname;type:varchar(100);not null;comment:真实姓名" json:"realname"`
	Avatar      *string  `gorm:"column:avatar;type:varchar(255);comment:用户头像" json:"avatar"`
	Mobile      *string  `gorm:"column:mobile;type:varchar(32);comment:手机号" json:"mobile"`
	Email       *string  `gorm:"column:email;type:varchar(100);comment:电子邮箱" json:"email"`
	LastLogin   *float64 `gorm:"column:last_login;type:decimal(16,0) unsigned;default:0;comment:最后登录时间" json:"last_login"`
	LastIP      string   `gorm:"column:last_ip;type:varchar(32);not null;comment:最后登录IP" json:"last_ip"`
	Status      int64    `gorm:"column:status;type:tinyint(1) unsigned;not null;default:1;comment:账号状态 1:正常 2:禁止登陆" json:"status"`
	AuthGroupID int64    `gorm:"column:auth_group_id;type:int(10) unsigned;not null;comment:权限id" json:"auth_group_id"`
	LoginStatus int64    `gorm:"column:login_status;type:int(1);not null;comment:1为在线，0不在线" json:"login_status"`
	Examine     *int64   `gorm:"column:examine;type:int(1);comment:0未审核，1审核" json:"examine"`
	AssistID    *int64   `gorm:"column:assist_id;type:int(10);comment:辅助用户编号" json:"assist_id"`
	Title       string   `gorm:"column:title;type:varchar(128);not null;comment:管理级别" json:"title"`
	Rules       string   `gorm:"column:rules;type:varchar(255);not null;comment:权限下标" json:"rules"`
	Name        *string  `gorm:"column:name;type:varchar(255);comment:VIP名称" json:"name"`
	Token       string   `json:"token"`
	ExpiresAt   int64    `json:"expiresAt"`
}

func SetLoginResponse(user system.AuthAdmin, token string, expireAt int64) *LoginResponse {
	return &LoginResponse{
		ID:          user.ID,
		Username:    user.Username,
		Realname:    user.Realname,
		Avatar:      user.Avatar,
		Mobile:      user.Mobile,
		Email:       user.Email,
		LastLogin:   user.LastLogin,
		LastIP:      user.LastIP,
		Status:      user.Status,
		AuthGroupID: user.AuthGroupID,
		LoginStatus: user.LoginStatus,
		Examine:     user.Examine,
		AssistID:    user.AssistID,
		Title:       user.AuthGroup.Title,
		Rules:       user.AuthGroup.Rules,
		Name:        user.Vip.Name,
		Token:       token,
		ExpiresAt:   expireAt,
	}

}
